import Vue from "vue";
import Vuex from "../myVuex/moduleVuex";

Vue.use(Vuex); //默认执行插件install方法

export default new Vuex.Store({
  state: {
    age: 10,
  },
  getters: {
    myAge(state) {
      return state.age * 2;
    },
  },
  mutations: {
    change(state, payload) {
      console.log('a')
      state.age += payload;
    },
    changeA(state, payload) {
      console.log('AAA')
      state.age += payload;
    },
    changeB(state, payload) {
      state.age += payload;
    },
  },
  actions: {
    asyncChange({
      commit
    }, payload) {
      setTimeout(() => {
        commit("change", payload);
      }, 1000);
    },
  },
  modules: {
    a: {
      state: {
        date: new Date().getSeconds,
      },
      // mutations: {
      //   change(state, payload) {
      //     state.age += payload;
      //   },
      // },
    },
    b: {
      state: {
        date: "b100",
      },
      mutations: {
        changemoduleB(state, payload) {
          console.log('bb')
          state.date += payload;
        },
      },
      modules: {
        c: {
          state: {
            date: "c100",
          },
        },
      },
    },
  },
});